﻿

CREATE VIEW [dbo].[VMonthlyResponsibleReport]
AS
select CustomerLoans.CommitteeID,Committees.CommitteeName,Users.UserID,Board.BoardNumber,
		CustomerLoans.LoanNumber,Customers.CustomerName,
		Customers.Gender,LoanType.LoanTypeName,CustomerLoans.IsLoanProjectExist,
		ProjectStages.Stage,CustomerLoans.LoanAmount,
		NumberOfInstallmentsTable.NoOfInstallments as InstallmentsCount,
		LoanExecution.TotalLoanAmount - dbo.LoanExecution.LoanAmount as Profit,
		LoanExecution.TotalLoanAmount,LoanPaymentMethod.LoanPaymentMethodName,
		LoanExecution.CheckNumber,LoanExecution.CheckDate,LoanExecution.ExecutionDate 
from CustomerLoans
	inner join Committees on CustomerLoans.CommitteeID = Committees.CommitteeID
	inner join BoardLoans on CustomerLoans.LoanID = BoardLoans.LoanID
	inner join Board on BoardLoans.BoardID = Board.BoardID
	inner join Customers on CustomerLoans.CustomerID = Customers.CustomerID
	inner join LoanType on LoanType.LoanTypeID = CustomerLoans.LoanTypeID
	inner join ProjectStages on CustomerLoans.ProjectStageID = ProjectStages.ProjectStageID
	inner join LoanExecution on LoanExecution.LoanID = CustomerLoans.LoanID
	inner join (select LoanExecutionID,count(LoanExecutionID) as NoOfInstallments
				from LoanExecutionInstallments
				group by LoanExecutionID) as NumberOfInstallmentsTable
			on NumberOfInstallmentsTable.LoanExecutionID = LoanExecution.LoanExecutionID
	inner join LoanPaymentMethod on LoanPaymentMethod.LoanPaymentMethodID = CustomerLoans.LoanPaymentMethodID 
	inner join Users on CustomerLoans.ResponsibleID = Users.UserID			


GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[62] 4[10] 2[4] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "wfProcessInstances"
            Begin Extent = 
               Top = 515
               Left = 446
               Bottom = 681
               Right = 617
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "wfProcesses"
            Begin Extent = 
               Top = 538
               Left = 168
               Bottom = 638
               Right = 320
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "wfStepInstances"
            Begin Extent = 
               Top = 579
               Left = 726
               Bottom = 694
               Right = 923
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "CustomerLoans"
            Begin Extent = 
               Top = 71
               Left = 12
               Bottom = 265
               Right = 205
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "LoanExecution"
            Begin Extent = 
               Top = 19
               Left = 300
               Bottom = 221
               Right = 493
            End
            DisplayFlags = 280
            TopColumn = 5
         End
         Begin Table = "LoanType"
            Begin Extent = 
               Top = 195
               Left = 718
               Bottom = 280
               Right = 873
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "ProjectStages"
            Begin Extent = 
               Top = 96
               Left = 915
               Bottom = 211
               Right = 1069
   ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'VMonthlyResponsibleReport'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane2', @value=N'         End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "Projects"
            Begin Extent = 
               Top = 6
               Left = 1138
               Bottom = 139
               Right = 1290
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "Customers"
            Begin Extent = 
               Top = 329
               Left = 145
               Bottom = 433
               Right = 342
            End
            DisplayFlags = 280
            TopColumn = 2
         End
         Begin Table = "BoardLoans"
            Begin Extent = 
               Top = 279
               Left = 385
               Bottom = 394
               Right = 583
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "Board"
            Begin Extent = 
               Top = 292
               Left = 685
               Bottom = 407
               Right = 837
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "LoanPaymentMethod"
            Begin Extent = 
               Top = 239
               Left = 1126
               Bottom = 354
               Right = 1335
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "Committees"
            Begin Extent = 
               Top = 313
               Left = 914
               Bottom = 428
               Right = 1077
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "Users"
            Begin Extent = 
               Top = 492
               Left = 1063
               Bottom = 607
               Right = 1215
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 22
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 3240
         Width = 1710
         Width = 3135
         Width = 3150
         Width = 3150
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 2145
         Alias = 1530
         Table = 1740
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'VMonthlyResponsibleReport'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=2 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'VMonthlyResponsibleReport'
GO


